<%--
  Created by IntelliJ IDEA.
  User: qjqe@outlook.com
  Date: 2020/5/15
  Time: 9:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@page import="java.util.List"%>
<script>

    /*修改
    点击之后页面变成可提交状态*/
    function xiugai(a){
        var trobj = a.parentNode.parentNode; //获得按钮所在行的行对象
        var tdobj = trobj.getElementsByTagName("td");
        for(var i =0;i<tdobj.length;i++){

            tdobj[i].innerHTML = "<input class='edit" + i + "'  style='max-width: 100px;' onblur='submit()' type=\"input\" value=" + tdobj[i].innerText + "  />";

        }
    }
    //修改后提交功能
    //异步提交
    function submit(){
        var teacherid=$(".edit0").val();
        var password=$(".edit1").val();
        var email=$(".edit2").val();
        var name=$(".edit3").val();
        var gender=$(".edit4").val();
        var username=$(".edit5").val();
        var phonenumber=$(".edit6").val();
        var position=$(".edit7").val();
        $.ajax(
            {
                url: "/teacher/edit",
                type: "post",
                datatype:"json",
                data:{"teacherid": teacherid,"password": password,"email":email,"name":name,"gender":gender,"username":username,"phonenumber":phonenumber,"position":position},
                success: function (result) { //返回的结果自动放在resut里面了

                    if (result.status == "success") {//请求成功
                        alert("成功");
                        location.reload();
                    } else {
                        alert("失败");
                        location.reload();
                    }
                }
            });
    }
    //点击添加按钮后的插入表格
    $(function () {
        $(".add").click(function () {
            $("tbody").prepend( "<tr><td><input class='add0'></td><td><input class='add1'></td><td><input class='add3'></td><td><input class='add4'></td><td><select class=\"form-control\"><c:forEach items = "${requestScope.department }" var="department"><option value=\"${department.departmentid }\">${department.departmentname }</option></c:forEach></select></td><th><button class=\"btn btn-default\" onclick=\"add()\">确定</button></th><th><button class=\"btn btn-default\" onclick=\"reload()\">取消</button></th></tr>");
        })
    })
    //点击删除按钮后的
    function del(a){

        $.ajax(
            {
                url: "/notice/delete",
                type: "post",
                datatype:"json",
                data:{"id":a},
                success: function (result) { //返回的结果自动放在resut里面了
                    if (result.status == "success") {//请求成功
                        alert("成功");
                        location.reload();
                    } else {
                        alert("失败");
                        location.reload();
                    }
                }
            });

    }
    //重新刷新
    function reload() {
        location.reload();
    }
    //插入功能里的提交数据
    function add() {
        var infoid=$(".add0").val();
        var name=$(".add1").val();
        var place=$(".add3").val();
        var number=$(".add4").val();
        var deparmentname=$("body").find('select option:selected').text();
        $.ajax(
            {
                url: "/notice/add",
                type: "post",
                datatype:"json",
                data:{"Infoid": infoid,"name": name,"place":place,"number":number,"Deparmentid":deparmentname},
                success: function (result) { //返回的结果自动放在resut里面了

                    if (result.status == "success") {//请求成功
                        alert("成功");
                        location.reload();
                    } else {
                        alert("失败");
                        location.reload();
                    }
                }
            });
    }
</script>

<h2 class="sub-header">通知列表</h2>
<div class="table-responsive">
    <table class="table table-striped">
        <thead>
        <tr>
            <th>编号</th>
            <th>标题</th>
            <!--<th>时间</th>-->
            <th>地点</th>
            <th>人数</th>
            <th>部门</th>
            <th><button class="btn btn-default btn-primary add">添加</button></th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items = "${requestScope.recruitInfos }" var="recruitInfos">
            <tr>
                <td >${recruitInfos.infoid }</td>
                <td >${recruitInfos.name }</td>
                <td >${recruitInfos.place }</td>
                <td >${recruitInfos.number }</td>
                <td >${recruitInfos.deparmentid }</td>
                <th><button class="btn btn-default delete" onclick="del(${recruitInfos.infoid })">删除</button></th>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
</div>